package spring.boot.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import spring.boot.admin.service.TProvinceService;

@Controller
@RequestMapping("/t/province")
public class TProvinceController {

    @Autowired
    private TProvinceService tProvinceService;

    /**
     * 初始化省市区全部数据
     */
    @PostMapping("init/all")
    @ResponseBody
    @PreAuthorize("true")
    public String init() {
        return tProvinceService.init();
    }


    /**
     * 跳转到管理页面
     */
    @GetMapping("to/list")
    @PreAuthorize("hasRole('T_PROVINCE_LIST')")
    public String toList() {
        return "province/list";
    }


    /**
     * 分页查询
     */
    @PostMapping("list")
    @ResponseBody
    @PreAuthorize("hasRole('T_PROVINCE_LIST')")
    public IPage list(@RequestParam(defaultValue = "1") Integer page,
                      @RequestParam(defaultValue = "10") Integer rows) {
        return tProvinceService.pageList(page, rows);
    }

}
